<?php
namespace Common\Model;
use Common\Model\BaseModel;
/**
* 标签model
*/
Class ContactModel extends BaseModel{
    // 添加标签
    public function addData($aid,$contact){
        if(empty($contact)){
            $this->error='联系人不能为空';
            return false;
        }else{
            foreach ($contact as $v) {
                if(!empty($v)){
                    $data=array(
                        'aid'=>$aid,
                        'c_name'=>$v['c_name'],
                        'role'=>$v['role'],
                        'tel'=>$v['tel'],
                        'email'=>$v['email'],
                        'wechat'=>$v['wechat']
                    );
                    $this->add($data);
                }
            }
            return true;
        }
    }




    // 根据Aid获取单条数据
    public function getDataByAid($aid){

       $data= $this->where(array('aid'=>$aid))->field('c_name,role,tel,email,wechat')->order('role desc')->select();
        foreach($data as $k=>$v){
            $data[$k]['role1']=makeoption('role')[$v['role']-1];
        }

        return $data;
    }


    public function deleteData($aid){

       $this->where(array('aid'=>$aid))->delete();

        return true;

    }




}
